package main

func main() {

	//root = [4,2,9,3,5,null,7]
	node3 := TreeNode{
		Val:   3,
		Left:  nil,
		Right: nil,
	}
	node4 := TreeNode{
		Val:   5,
		Left:  nil,
		Right: nil,
	}
	node5 := TreeNode{
		Val:   7,
		Left:  nil,
		Right: nil,
	}
	node1 := TreeNode{
		Val:   2,
		Left:  &node3,
		Right: &node4,
	}
	node2 := TreeNode{
		Val:   9,
		Left:  nil,
		Right: &node5,
	}
	root := TreeNode{
		Val:   4,
		Left:  &node1,
		Right: &node2,
	}

	//打印测试用例返回结果
	resp := inorderTraversal(&root)
	for _, v := range resp {
		println(v)
	}

}

//Definition for a binary tree node.
type TreeNode struct {
	Val   int
	Left  *TreeNode
	Right *TreeNode
}

func inorderTraversal(root *TreeNode) []int {
	arr := []int{}
	inorderTraversal1(root, &arr)
	return arr
}

func inorderTraversal1(root *TreeNode, arr *[]int) {
	if root == nil {
		return
	}
	inorderTraversal1(root.Left, arr)
	*arr = append(*arr, root.Val)
	inorderTraversal1(root.Right, arr)
}
